package com.example.kakaofragment;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.Toast;

public class MainActivity extends FragmentActivity {

	TabHost mTabHost;
	TabManager mTabManager;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		mTabHost = (TabHost) findViewById(android.R.id.tabhost);
		mTabHost.setup();

		mTabManager = new TabManager(this, mTabHost, R.id.realtabcontent);

		
		
		mTabManager.addTab(mTabHost.newTabSpec("tab1")
				.setIndicator("친구", getResources().getDrawable(R.drawable.tab1)),
				FragmentOne.class, null);
		mTabManager.addTab(mTabHost.newTabSpec("tab2")
				.setIndicator("채팅",getResources().getDrawable(R.drawable.tab2)),
				FragmentTwo.class, null);
		mTabManager.addTab(mTabHost.newTabSpec("tab3")
				.setIndicator("친구찾기",getResources().getDrawable(R.drawable.tab3)),
				FragmentThree.class, null);
		mTabManager.addTab(mTabHost.newTabSpec("tab4")
				.setIndicator("더보기",getResources().getDrawable(R.drawable.tab4)),
				FragmentFour.class, null);
		
//		mTabManager.addTab(mTabHost.newTabSpec("tab1")
//				.setIndicator("", getResources().getDrawable(R.drawable.tab1)),
//				FragmentOne.class, null);
//		mTabManager.addTab(mTabHost.newTabSpec("tab2")
//				.setIndicator("",getResources().getDrawable(R.drawable.tab2)),
//				FragmentTwo.class, null);
//		mTabManager.addTab(mTabHost.newTabSpec("tab3")
//				.setIndicator("",getResources().getDrawable(R.drawable.tab3)),
//				FragmentThree.class, null);
//		mTabManager.addTab(mTabHost.newTabSpec("tab4")
//				.setIndicator("",getResources().getDrawable(R.drawable.tab4)),
//				FragmentFour.class, null);
		
//		mTabHost.setBackgroundColor(Color.argb(150, 22, 70, 150)); 
		
		// ★반드시 이거 해야됨★
		if (savedInstanceState != null) {
			mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
		}
		
		User user = new User();
    	if( user.id != "" & user.pw != "")
    	{
    		 Toast. makeText(this, "로그인 되었습니다.", Toast. LENGTH_SHORT).show();
    	}
		
	}

	// ★반드시 이것도 해야됨★
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		outState.putString("tab", mTabHost.getCurrentTabTag());
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
    boolean isConfirmed = false;
   Handler handler = new Handler();
   
    @Override
    public void onBackPressed() {
           // TODO Auto-generated method stub
           if(isConfirmed )
          {
                 finish();
          } else
          {
                 Toast. makeText(this, "뒤로가기 버튼을 다시 누르면 종료됩니다", Toast. LENGTH_SHORT).show();
                  isConfirmed = true ;
                 
                  handler.postDelayed( new Runnable() {
                       
                        @Override
                        public void run() {
                               // TODO Auto-generated method stub
                               isConfirmed = false ;
                              
                       }
                 }, 2000);
          }
   }
    
    @Override
    protected void onResume() {
    	// TODO Auto-generated method stub
    	super.onResume();
    }


}
